package com.midou.administration.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.midou.administration.bo.DishTypeBo;
import com.midou.administration.bo.DishTypePagination;
import com.midou.administration.entity.DishType;
import com.midou.administration.service.DishTypeService;
import com.midou.administration.service.impl.DishTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author MrChen
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/administration/dish-type")
public class DishTypeController {

    @Autowired
    private DishTypeServiceImpl dishType;

    @Autowired
    private DishTypeService dishTypeService;

  /**
   * 查询全部菜品分类
   * @return 菜品分类集合
   */
  @RequestMapping("findDishTypeAll")
  public Page<DishType> findAll(@RequestBody DishTypePagination dishTypePagination){
    this.dishType.findAll(dishTypePagination);
    return this.dishType.findAll(dishTypePagination);
  }

  /**
   * 添加菜品分类
   * @param DishTypeName 前台接受的分类名
   * @param bsid 获取前台token中的商铺id
   * @return 受影响的行数
   */
  @RequestMapping("addDishType")
  public int addDishType(@RequestBody DishType dishType){
    int count = this.dishType.addDishType(dishType);
    return count;
  }

  /**
   * 删除菜品分类
   * @param id 前台传入的分类id
   * @return 受影响的行数
   */
  @RequestMapping("delDishType")
  public int delDishType(@RequestBody int id){
    int count = this.dishType.delDishType(id);
    return count;
  }

  /**
   * 修改
   * @param dishType 前台传入的集合
   * @return
   */
  @RequestMapping("updDishTypeName")
  public int updDishTypeName(@RequestBody DishType dishType){
    int count =  this.dishType.updDishTypeName(dishType);
    return count;
  }

  /**
   * 判断分类名是否存在
   * @param dishTypeName
   * @return
   */
  @RequestMapping("judgmentDishTypeName")
  public int judgmentDishTypeName(@RequestBody String dishTypeName){
    int count = this.dishType.judgmentDishTypeName(dishTypeName);
    return count;
  }

  /**
   *冯浩奇的
   */
  @RequestMapping("/fenlei")
  public List<DishTypeBo> qurey(){
    return dishTypeService.query();
  }

  /**
   * 查询属于该商家的所有菜品分类
   * @param business 门店id
   * @return
   */
  @RequestMapping("/queryBybusiness")
  public List<DishType> queryBybusiness(@RequestBody  DishType business){
    List<DishType> list =  this.dishTypeService.queryBybusiness(business.getBusinessId());
    return list;
  }
}
